#include "frmstudlst.h"
#include "ui_frmstudlst.h"

FrmStudlst::FrmStudlst(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::FrmStudlst)
{
    ui->setupUi(this);
    this->initForm();
}

FrmStudlst::~FrmStudlst()
{
    delete ui;
}

void FrmStudlst::initForm()
{
    ui->tableWidget->setColumnCount(4);
    ui->tableWidget->setRowCount(3);

    ui->tableWidget->setHorizontalHeaderLabels(QStringList()<<"姓名"<<"性别"<<"年级"<<"第一次培训时间");

    ui->tableWidget->horizontalHeader()->setSectionResizeMode(QHeaderView::ResizeMode::Stretch);

    QList<StudModel> lst=QTECHSchedDataHelper::getStudents();
    foreach (StudModel m, lst) {
        QString strSex=m.getSex()==0?"男":"女";
        QDate curDate=QDate::currentDate();
        int y1=curDate.year(),m1=curDate.month();
        int y2=m.getEnrolDate().year(),m2=m.getEnrolDate().month();
        int grade=y1-y2-m.getReptnum();
        if(m1>m2)
        {
            grade +=1;
        }
        QString strGrade=QString("%1年级").arg(y1-y2+1-m.getReptnum());
        QString strTrainDate=m.getEnrolTrainDate().toString("yyyy-MM-dd");
        appendRow(QStringList()<<m.getName()<<strSex<<strGrade<<strTrainDate);
    }
}

void FrmStudlst::appendRow(const QStringList lst)
{
    static qint16 row=0;
    qint16 col=0;
    foreach (QString str, lst) {
        QTableWidgetItem *item=new QTableWidgetItem(str);
        item->setTextAlignment(Qt::AlignLeft);

        ui->tableWidget->setItem(row,col++,item);
    }

    row++;
}
